package main

import (
	"fmt"
	"sync"
)

var a chan int = make(chan int,2)
var b chan int = make(chan int)
var wg sync.WaitGroup
func main() {
	wg.Add(2)
	go f1(a)
	go f2(a,b)
	for{
		i,ok:=<-b
		if !ok{
			break
		}
		fmt.Println("从c2中取出一个值是",i)
	}
	wg.Wait()

}
func f1(c chan int) {
	defer wg.Done()
	for i:=0;i<100;i++{
		c<-i
		//fmt.Println("放入一个值到c1中")
	}
	close(c)
}
func f2(c1 chan int, c2 chan int)  {
	defer wg.Done()
	for {
		i,ok := <-c1
		//fmt.Println("从c1中取出一个值")
		if !ok{
			break
		}
		c2<-i*i
	}
	defer close(c2)
}